let aid

function _edit(el) {
    let hidden = $(el).parent().prev().find(":hidden");
    aid = hidden[7].value
    $("#description").val(hidden[0].value)
    $("#category").val(hidden[1].value)
    $("#total").val(hidden[2].value)
    $("#model_title").text(hidden[3].value)
    $("#title").val(hidden[3].value)
    $("#tags").val(hidden[4].value)
    $("#permission").val(hidden[5].value)
    $("#number").val(hidden[6].value)
    if (hidden[1].value == 0) {
        $("#total").attr("disabled", true)
        $("#number").attr("disabled", true)
    } else {
        $("#total").attr("disabled", false)
        $("#number").attr("disabled", false)
    }
    $("#video_edit").modal({
        show: true,
        keyboard: false
    })

}

function _delete(el) {
    if (confirm("确认删除吗？")) {

    }else {
        return
    }
    let aid=[]
    aid.push($(el).parent().prev().find("input:hidden:eq(7)").val())
    $.ajax({
        type: "POST",
        url: "/video/delete",
        data: {
            ids:aid
        },
        dataType: "json",
        success:function (data) {
            if (data.code==200){
                if (confirm("删除成功")){
                    location.reload();
                } else{
                    location.reload();
                }
            }else{
                alert("删除失败")
            }
        },
        error:function(data){
            alert("出错啦，请联系管理员")
        }
    })

}


function deleteVideo(aid){
    $.ajax({
        type: "POST",
        url: "/video/delete",
        data: {
            id:aid,
        },
        dataType: "json",
        success:function (data) {
            if (data.code==200){
                if (confirm("删除成功")){
                    location.reload();
                } else{
                    location.reload();
                }
            }else{
                alert("删除失败")
            }
        },
        error:function(data){
            alert("出错啦，请联系管理员")
        }
    })
}

function _deleteAll() {

    if (confirm("确认删除吗？")) {

    }else {
        return
    }
    let id=[]
    let aids=$("input:checkbox:not(:first):checked").parent().parent().find("input:hidden:eq(7)")
    for (let i=0;i<aids.length;i++){
        id.push(aids[i].value);
    }

    $.ajax({
        type: "POST",
        url: "/video/delete",
        data: {
            ids:id,
        },
        dataType: "json",
        success:function (data) {
            if (data.code==200){
                if (confirm("删除成功")){
                    location.reload();
                } else{
                    location.reload();
                }
            }else{
                alert("删除失败")
            }
        },
        error:function(data){
            alert("出错啦，请联系管理员")
        }
    })


}



function _selectAll(el) {
    $("input:checkbox").attr("checked", el.checked);
}

function _submit() {
    console.log($("#update_form").serializeArray());
    $.ajax({
        type: "POST",
        url: "/video/update/" + aid,
        data: {
            description: $("#description").val(),
            category: $("#category").val(),
            total: $("#total").val(),
            title: $("#title").val(),
            tags: $("#tags").val(),
            permission: $("#permission").val(),
            number: $("#number").val()

        },
        dataType: "json",
        success: function (data) {
            if (data.code == 200) {
                if (confirm("修改成功")){
                    location.reload();
                } else{
                    location.reload();
                }
            } else {
                alert("修改失败")
            }
        },
        error: function (data) {
            alert("修改失败error")
        }

    })
}

function _changeVideo(el) {
    if (el.value == 0) {
        $("#total").attr("disabled", true)
        $("#number").attr("disabled", true)
    } else {
        $("#total").attr("disabled", false)
        $("#number").attr("disabled", false)
    }
}


$("#searchSubmit").click(function () {
    console.log($("#look_video").text() == '影片浏览');
    let select_seach=$("#select_seach").text().toString();
    let searchword=$("#searchWord").val()
    if (select_seach=='选择搜索分类'){
        alert("请选择分类")
        return false
    }
    if (searchword.length==0){
        alert("请输入关键词")
        return false
    }

    if ($("#look_video").text()=='影片浏览'){
        window.open("/video_back/find_like_look?select="+select_seach+"&input="+searchword)
    } else {
        window.open("/video_back/find_like?select="+select_seach+"&input="+searchword)

    }
    return false
})